var urlArgs = Suningmatch.getUrlArgs();

var vm = new Vue({
    el: '#home',
    data: {
        user: {},
        isanonymous: false,
        nmObj: {},
        criticType: 1,
        nmimg: "",
        commContent: "test1211",
        uploadPop: false,
        
    },
    computed: {
        surplusNum: function(){
             
        }
    },
    methods: {
        whitecomm: function(){
            // 
            if(vm.isanonymous){
                vm.criticType = 3;
            }else{
                var ua = window.navigator.userAgent.toLowerCase(); 
                if(ua.match(/MicroMessenger/i) == 'micromessenger'){
                    vm.criticType = 2;
                }
            }
            
            $.ajax({
                type: "post",
                url: Suningmatch.DI.whiteComm,
                data: {
                    "topicId": urlArgs.topicId,
                    "criticType": vm.criticType,
                    "nmHeadPic":vm.isanonymous?vm.nmObj.headPic:null,
                    "nmName": vm.isanonymous?vm.nmObj.name:null,
                    "commContent": vm.commContent
                },
                dataType: "json",
                success: function(response) {
                    console.log("xie ping lun")
                },
                error: function(err) {
                    console.log(err);
                }
            });
        },
        anonymousWhite: function(){
            vm.isanonymous = !vm.isanonymous;
            if(!vm.isanonymous){
                this.nmObj = {
                    name: urlArgs.wx_nickname,
                    headPic: urlArgs.wx_headimgurl
                }
                return;
            }
            $.ajax({
                type: "post",
                url: Suningmatch.DI.getNmInfo,
                dataType: "json",
                success: function(response) {
                    vm.nmObj = response.data;
                },
                error: function(err) {
                    console.log(err);
                }
            });
        },
        changePic: function(){
            $.ajax({
                type: "post",
                url: Suningmatch.DI.getNmInfo,
                dataType: "json",
                success: function(response) {
                     vm.nmObj = response.data.data;
                },
                error: function(err) {
                    console.log(err);
                }
            });
        },
        replaceImg: function(){
            setTimeout(function(){
                vm.uploadPop = true;    
            },1000);
            
            cropperImg();
        },
        uploadImg: function(){
            //调用上传图片接口
            //创建FormData对象
            var data = new FormData();
            //为FormData对象添加数据
            $.each($('#cropper-input')[0].files, function(i, file) {
                data.append('upload_file', file);
            });
            data.append('x', $("#preview-x").val());
            data.append('y', $("#preview-y").val());
            data.append('width', $("#preview-width").val());
            data.append('height', $("#preview-height").val());
            
            $.ajax({
                type: "post",
                url: Suningmatch.DI.getNmInfo,
                dataType: "json",
                data: data,
                contentType: false,    //不可缺
                processData: false,    //不可缺
                success: function(response) {
                    console.log("等着上传成功！")
                },
                error: function(err) {
                    console.log(err);
                }
            });
        }
    },
    ready: function() {
        this.user = {
            nickname: urlArgs.wx_nickname,
            nickimg: urlArgs.wx_headimgurl
        }
        this.nmObj = {
            name: urlArgs.wx_nickname,
            headPic: urlArgs.wx_headimgurl
        }
    }
});
